import {
    request_post
} from '../../utils/request';
Page({
    data: {
        tips: null,
        waitSecond: 10,
        intervalId: null,
        options: null
    },
    onLoad(options) {
        this.setData({options : options})
        if (this.data.intervalId) clearInterval(this.data.intervalId)
        wx.setNavigationBarTitle({
            title: options.type == 'ATTENTION' ? '复习攻略' : '真题示例',
        })

        request_post('/exam-tips/get-for-show', {
            basicCode: options.code,
            type: options.type
        }).then(res => {
            this.setData({
                tips: res
            })
            this.setData({
                intervalId: setInterval(() => {
                    this.setData({
                        waitSecond: this.data.waitSecond - 1
                    })
                    if (this.data.waitSecond <= 0) clearInterval(this.data.intervalId)
                }, 1000)
            })
        })
    },
    confirm() {
        request_post('/exam-tips/confirm', {
            basicCode: this.data.options.code,
            type: this.data.options.type
        }).then(res => {
            wx.navigateBack({
                delta: 1
            })
        })
    }
})